package com.gy.zpchat.ui.meeting.adapter;

import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import im.zego.zim.enums.ZIMCallUserState;
import com.gy.zpchat.R;

public class InMeetingUserHolder extends RecyclerView.ViewHolder{

    private final TextView tv_role;
    private final TextView tv_username;
    private final TextView tv_state;
    private final TextView tv_timeout;
    private final CheckBox cb_choose;

    public InMeetingUserHolder(@NonNull ViewGroup viewGroup) {
        super(LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_user_in_meeting, viewGroup, false));
        tv_role = itemView.findViewById(R.id.tv_role);
        tv_username = itemView.findViewById(R.id.tv_username);
        tv_state = itemView.findViewById(R.id.tv_state);
        tv_timeout = itemView.findViewById(R.id.tv_timeout);
        cb_choose = itemView.findViewById(R.id.cb_choose);
    }

    public CheckBox getChooseView(){
        return cb_choose;
    }

    public void setData(CallData meetingData, String creatorID){
        if (meetingData.getCallUserInfo().userID.equals(creatorID)){
            tv_role.setText("创建者");
        }else {
            tv_role.setText("参会者");
        }

        tv_username.setText(meetingData.getCallUserInfo().userID);

        ZIMCallUserState state = meetingData.getCallUserInfo().state;
        if (state == ZIMCallUserState.ACCEPTED){
            tv_state.setText("已接受");
        }else if (state == ZIMCallUserState.CANCELLED){
            tv_state.setText("已取消");
        }else if (state == ZIMCallUserState.INVITING){
            tv_state.setText("邀请中");
        }else if (state == ZIMCallUserState.OFFLINE){
            tv_state.setText("离线中");
        }else if (state == ZIMCallUserState.RECEIVED){
            tv_state.setText("已收到");
        }else if (state == ZIMCallUserState.REJECTED){
            tv_state.setText("已拒绝");
        }else if (state == ZIMCallUserState.QUITED){
            tv_state.setText("退出");
        }else if (state == ZIMCallUserState.TIMEOUT){
            tv_state.setText("超时");
        }else if (state == ZIMCallUserState.UNKNOWN){
            tv_state.setText("未知");
        }else {
            tv_state.setText(state.toString());
        }
        tv_timeout.setText(String.valueOf(meetingData.getTimeout()));
    }

}
